<?php
namespace app\web\controller;

use app\model\Theme; 

class Reply extends Base
{
    public function Reply()
    {
global $_G, $_P;
//load_func('tpl');
$system = $_G['system'];
$_G['page']['title'] = '评论列表-' . $system['sysname'];;
$replyid = intval($_P['replyid']);

$GLOBALS['frames'] = array();
$themeid = intval($_P['themeid']);
if($themeid <= 0){
	$themeid = Theme::getDefaultThemenew($_G['mpid']);
}
if(empty($themeid)){
	return_msg('还没有创建活动,请联系管理员');
}

$config = 	Theme::getConfig($themeid);
$do = 'reply';
$op = !empty($_P['op']) ? $_P['op'] : 'display';
$url = createWebUrl('reply',array('op' => 'display','themeid'=>$themeid));



if($op == 'display') {
	
	if (!empty($_P['content'])) {
		foreach ($_P['content'] as $id => $content) {
			$update = array(
					'content' => $content['content'],
			);
			db_update(t_reply, $update, array('id' => $id));
		}
		return_tips('更新成功！', 'refresh', 'success');
	}
	
	
	$condition = ' g.uniacid = :uniacid';
	$params[':uniacid'] = $_G['mpid'];
	$condition .= ' and g.themeid = :themeid';
	$params[':themeid'] = $themeid;

	$pindex = max(1, intval($_P['page']));
	$psize = 20;

	$total = db_fetchcolumn('SELECT COUNT(*) FROM ' . tablename(t_reply) . ' as g WHERE ' . $condition, $params);
	$sql = 'SELECT g.* FROM ' . tablename(t_reply) . ' as g 
			WHERE ' . $condition . ' ORDER BY g.id desc LIMIT '.($pindex - 1) * $psize.','.$psize;
	$list = db_select($sql, $params);

	$pager = pagination($total, $pindex, $psize);
}

if($op == 'status') {
	$status = intval($_P['status']);
	$state = db_update(t_reply, array('status' => $status), array('uniacid' => $_G['mpid'], 'id' => $replyid));
	return_tips(error(0, ''), '', 'ajax');
}

if($op == 'delete') {
	db_delete(t_reply, array('uniacid' => $_G['mpid'],'id' => $replyid));
	return_tips('删除成功', $url, 'success');
}



$return_clicent = get_defined_vars();
return view('/reply' , $return_clicent);
}
}